package com.ruoyi.project.system.shOperationLog.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.shOperationLog.domain.ShOperationLog;
import com.ruoyi.project.system.shOperationLog.service.IShOperationLogService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 操作日志Controller
 * 
 * @author ruoyi
 * @date 2021-05-28
 */
@Controller
@RequestMapping("/system/shOperationLog")
public class ShOperationLogController extends BaseController
{
    private String prefix = "system/shOperationLog";

    @Autowired
    private IShOperationLogService shOperationLogService;

    @RequiresPermissions("system:shOperationLog:view")
    @GetMapping()
    public String shOperationLog()
    {
        return prefix + "/shOperationLog";
    }

    /**
     * 查询操作日志列表
     */
    @RequiresPermissions("system:shOperationLog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShOperationLog shOperationLog)
    {
        startPage();
        List<ShOperationLog> list = shOperationLogService.selectShOperationLogList(shOperationLog);
        return getDataTable(list);
    }

    /**
     * 导出操作日志列表
     */
    @RequiresPermissions("system:shOperationLog:export")
    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShOperationLog shOperationLog)
    {
        List<ShOperationLog> list = shOperationLogService.selectShOperationLogList(shOperationLog);
        ExcelUtil<ShOperationLog> util = new ExcelUtil<ShOperationLog>(ShOperationLog.class);
        return util.exportExcel(list, "操作日志数据");
    }

    /**
     * 新增操作日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存操作日志
     */
    @RequiresPermissions("system:shOperationLog:add")
    @Log(title = "操作日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShOperationLog shOperationLog)
    {
        return toAjax(shOperationLogService.insertShOperationLog(shOperationLog));
    }

    /**
     * 修改操作日志
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ShOperationLog shOperationLog = shOperationLogService.selectShOperationLogById(id);
        mmap.put("shOperationLog", shOperationLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存操作日志
     */
    @RequiresPermissions("system:shOperationLog:edit")
    @Log(title = "操作日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShOperationLog shOperationLog)
    {
        return toAjax(shOperationLogService.updateShOperationLog(shOperationLog));
    }

    /**
     * 删除操作日志
     */
    @RequiresPermissions("system:shOperationLog:remove")
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shOperationLogService.deleteShOperationLogByIds(ids));
    }
}
